package com.sls.game.dao.enfu.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.enfu.EnfuAreaDAO;
import com.sls.game.dao.impl.SuperDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.enfu.EnfuAreaInfo;

/**
 * 
 * @description 恩付商品可充区域--DAO
 * @author Wangxuegang
 * @date 2013-4-28
 */
@Repository("enfuAreaDAO")
public class EnfuAreaDAOImpl extends SuperDAO<EnfuAreaInfo> implements
		EnfuAreaDAO {

	/**
	 * 记录插入
	 * 
	 * @param enfuAreaInfo
	 */
	@Override
	public void insert(EnfuAreaInfo enfuAreaInfo) {
		this.getSqlSession().insert("mybatis.xml.EnfuAreaMapper.insert",
				enfuAreaInfo);
	}

	/**
	 * 通过goodsId,gameAreaName查询一条记录
	 * 
	 * @param enfuAreaInfo
	 * @return
	 */
	@Override
	public List<EnfuAreaInfo> queryOneOrMoreGameArea(EnfuAreaInfo enfuAreaInfo) {
		List<EnfuAreaInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.EnfuAreaMapper.queryOneOrMoreGameArea",
				enfuAreaInfo);

		return list;
	}

	/**
	 * 删除记录
	 * 
	 * @param id
	 */
	@Override
	public void deleteById(String id) {
		this.getSqlSession()
				.delete("mybatis.xml.EnfuAreaMapper.deleteById", id);
	}

	// ===================================================

	/**
	 * 记录查询
	 * 
	 * @param enfuAreaInfo
	 * @return
	 */
	@Override
	public String queryGameArea(EnfuAreaInfo enfuAreaInfo) {
		String id = null;
		id = this.getSqlSession().selectOne(
				"mybatis.xml.EnfuAreaMapper.queryGameArea", enfuAreaInfo);
		return id;
	}

	/**
	 * 记录更新
	 * 
	 * @param enfuAreaInfo
	 */
	@Override
	public void updateInfo(EnfuAreaInfo enfuAreaInfo) {
		this.getSqlSession().update("mybatis.xml.EnfuAreaMapper.updateInfo",
				enfuAreaInfo);
	}

	/**
	 * 根据gameid和areaname查询areaid的值
	 * 
	 * @param enfuAreaInfo
	 * @return
	 */
	@Override
	public EnfuAreaInfo queryEnfuAreaInfo(EnfuAreaInfo enfuAreaInfo) {
		EnfuAreaInfo info = null;
		info = this.getSqlSession().selectOne(
				"mybatis.xml.EnfuAreaMapper.queryEnfuAreaInfo", enfuAreaInfo);
		return info;
	}

	/**
	 * 根据productid查询区域表
	 * 
	 * @param productid
	 * @return
	 */
	@Override
	public List<EnfuAreaInfo> queryEnfuAreaList(String productid) {
		List<EnfuAreaInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.EnfuAreaMapper.queryEnfuAreaList", productid);
		return list;
	}

	/**
	 * 大区分页查询
	 * 
	 * @param areaInfo
	 * @return
	 */
	@Override
	public Pagination<EnfuAreaInfo> queryPaginationList(EnfuAreaInfo areaInfo) {
		Pagination<EnfuAreaInfo> paginationList = null;
		int rowCount = queryRowCount(areaInfo);
		areaInfo.calculate();
		List<EnfuAreaInfo> list = queryResultList(areaInfo);
		paginationList = queryPagination(rowCount, list, areaInfo);
		return paginationList;
	}

	/**
	 * 查询记录总数
	 * 
	 * @param areaInfo
	 * @return
	 */
	private int queryRowCount(EnfuAreaInfo areaInfo) {
		int rowCount = 0;
		rowCount = this.getSqlSession().selectOne(
				"mybatis.xml.EnfuAreaMapper.queryRowCount", areaInfo);
		return rowCount;
	}

	/**
	 * 查询结果记录集
	 * 
	 * @param detailInfo
	 * @return
	 */
	private List<EnfuAreaInfo> queryResultList(EnfuAreaInfo areaInfo) {
		List<EnfuAreaInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.EnfuAreaMapper.queryResultList", areaInfo);
		return list;
	}

}
